#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
#define MAX 1000
#define oo (1<<30)
#define MAXS 200
int w[MAXS][MAXS];
int lx[MAXS],ly[MAXS];
int linky[MAXS];
int visx[MAXS],visy[MAXS];
int slack[MAXS];
char words[200][MAX+1];
int L[200];
int n;
bool find(int x){
	visx[x]=true;
	for(int y=0;y<n;++y){
		if(visy[y])continue;
		int t=lx[x]+ly[y]-w[x][y];
		if(t==0){
			visy[y]=true;
			if(linky[y]==-1||find(linky[y])){
				linky[y]=x;
				return true;
			}
		}
		else slack[y]=min(slack[y],t);
	}
	return false;
}
int KM(){
	memset(linky,-1,sizeof(linky));
	memset(lx,0,sizeof(lx));
	memset(ly,0,sizeof(ly));
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			lx[i]=max(w[i][j],lx[i]);
	for(int x=0;x<n;x++){
		while(1){
			memset(visx,0,sizeof(visx));
			memset(visy,0,sizeof(visy));
			memset(slack,0x11,sizeof(slack));
			if(find(x))break;
			int d=oo;
			for(int i=0;i<n;++i)
				if(!visy[i])
					d=min(d,slack[i]);
			for(int i=0;i<n;++i)
				if(visx[i])
					lx[i]-=d;
			for(int i=0;i<n;++i)
				if(visy[i])
					ly[i]+=d;
		}
	}
	int res=0;
	for(int i=0;i<n;i++)
		if(linky[i]!=-1)
			res+=w[linky[i]][i];
	return res;
}
int main() {
	int c1,c2;
	while(scanf("%d",&n)!=EOF) {
		for(int i=0;i<n;i++) {
			scanf("%s",words[i]);
			L[i]=strlen(words[i]);
		}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++) {
				w[i][j]=0;
				if(i==j) continue;
				c1=L[i]-1,c2=0;
				while((c1>=0&&c2<L[j])&&words[i][c1]==words[j][c2]) {
					w[i][j]++;
					c1--;c2++;
				}
			}
		printf("%d\n",KM());
	}
	return 0;
}



